#include "VSDepthStencil.h"
#include "VSGraphicInclude.h"
#include "VSStream.h"
using namespace VSEngine2;
IMPLEMENT_RTTI_NoCreateFun(VSDepthStencil,VSBind)
BEGIN_ADD_PROPERTY(VSDepthStencil,VSBind)
REGISTER_PROPERTY(m_uiWidth,Width,VSProperty::F_SAVE_LOAD_CLONE)
REGISTER_PROPERTY(m_uiHeight,Height,VSProperty::F_SAVE_LOAD_CLONE)
REGISTER_PROPERTY(m_uiMulSample,MulSample,VSProperty::F_SAVE_LOAD_CLONE)
REGISTER_PROPERTY(m_uiFormatType,FormatType,VSProperty::F_SAVE_LOAD_CLONE)
END_ADD_PROPERTY
IMPLEMENT_INITIAL_NO_CLASS_FACTORY_BEGIN(VSDepthStencil)
IMPLEMENT_INITIAL_NO_CLASS_FACTORY_END
VSDepthStencil::VSDepthStencil()
{

}
VSDepthStencil::VSDepthStencil(unsigned int uiWidth,unsigned int uiHeight,
							   unsigned int uiMulSample,unsigned int uiFormatType)
{
	m_uiWidth = uiWidth;
	m_uiHeight = uiHeight;
	VSMAC_ASSERT(uiMulSample < VSRenderer::MS_MAX)
	VSMAC_ASSERT(uiFormatType < VSRenderer::SFT_MAX)
	m_uiMulSample = uiMulSample;
	m_uiFormatType = uiFormatType;
	m_bIsStatic = 1;
}
VSDepthStencil::~VSDepthStencil()
{
	ReleaseResource();
}
unsigned int VSDepthStencil::DiskUse()const
{
	unsigned int Use = VSBind::DiskUse();

	Use += sizeof(unsigned int) * 4;

	return Use;

}
bool VSDepthStencil::Save(VSStream & rStream,unsigned int &iSaveUse)const
{
	if(!VSBind::Save(rStream,iSaveUse))
		return false;


	if(!rStream.Write(&m_uiWidth,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	if(!rStream.Write(&m_uiHeight,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	if(!rStream.Write(&m_uiMulSample,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	if(!rStream.Write(&m_uiFormatType,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	return 1;
}
bool VSDepthStencil::Load(VSStream & rStream,unsigned int &iSaveUse)
{

	if(!VSBind::Load(rStream,iSaveUse))
		return false;



	if(!rStream.Read(&m_uiWidth,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	if(!rStream.Read(&m_uiHeight,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	if(!rStream.Read(&m_uiMulSample,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);

	if(!rStream.Read(&m_uiFormatType,sizeof(unsigned int)))
		return 0;
	iSaveUse += sizeof(unsigned int);
	return 1;
}
bool VSDepthStencil::Clone(const VSObject *pObject,unsigned int uiType)
{
	const VSDepthStencil* Temp = DynamicCast<VSDepthStencil>(pObject); 
	if(!Temp)
		return 0;
	if(VSBind::Clone(pObject,uiType))
	{


		m_uiWidth = Temp->m_uiWidth;
		m_uiHeight =Temp->m_uiHeight;
		m_uiMulSample = Temp->m_uiMulSample;
		m_uiFormatType = Temp->m_uiFormatType;

		return 1;
	}
	else
	{
		return 0;

	}
}
bool VSDepthStencil::OnLoadResource(VSResourceIdentifier *&pID)
{
	if(!m_pUser)
		return 0;
	if(!m_pUser->OnLoadDepthStencil (this,pID))
		return 0;
	return 1;
}
bool VSDepthStencil::OnReleaseResource(VSResourceIdentifier *pID)
{
	if(!m_pUser)
		return 0;
	if(!m_pUser->OnReleaseDepthStencil(pID))
		return 0;
	return 1;
}